package si.cir.util;

import java.util.ArrayList;
import java.util.List;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

import si.cir.entities.Zagovor;

public class ZagovorHandler extends DefaultHandler{
	
	private List<Zagovor> zagovori = new ArrayList<Zagovor>();
	private Zagovor zagovor;
	private String currentElement = "";

	
	@Override
	public void startElement(String uri, String localName, String qName,
			Attributes attributes) throws SAXException {
		
		currentElement = "";
		if(qName.equals("Zagovor"))	{
			zagovor = new Zagovor();
		}
	}
	
	@Override
	public void endElement(String uri, String localName, String qName)
			throws SAXException {
		if(qName.equals("Zagovor")){
			zagovori.add(zagovor);
		}
		
		else if (qName.equals("ImeKandidata"))
		{
			zagovor.setKandidat(currentElement);
		}
		else if (qName.equals("NaslovDiplomskegaDela"))
		{
			zagovor.setNaslov(currentElement);
		}
		else if (qName.equals("DatumInMestoZagovora"))
		{
			zagovor.setDatumInMestoZagovora(currentElement);
		}
	}
	
	
	@Override
	public void characters(char[] ch, int start, int length)
			throws SAXException {
		currentElement = new String(ch, start, length);
	}
	
	public List<Zagovor> getZagovori(){
		return zagovori;
	}
}

